import { Component, OnInit } from '@angular/core';
import {FormControl} from '@angular/forms';
import {CamTypeService} from "../../shared/service/cam-type.service";

@Component({
  selector: 'app-type-search',
  templateUrl: './type-search.component.html',
  styleUrls: ['./type-search.component.css']
})
export class TypeSearchComponent implements OnInit {
  public searchParam: FormControl = new FormControl();
  constructor(private camTypeService:CamTypeService) {
    this.searchParam.valueChanges
      .debounceTime(500)
      .subscribe(
        value => {
          this.camTypeService.searchEvent.emit(value);
        }
      );

    this.camTypeService.searchFreshEvent.subscribe(
      param => {
        if (param) {
          this.searchParam.patchValue("");
        }
      }
    );
  }

  ngOnInit() {
  }

}
